package com.hckjsec.cloud.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hckjsec.cloud.domain.AppletsAdministration.*;
import com.hckjsec.cloud.domain.AppletsApplicantUser;
import com.hckjsec.cloud.domain.AppletsBusiness;
import com.hckjsec.cloud.domain.AppletsBusinessMatter;
import com.hckjsec.cloud.domain.homeView.AppletsCategoryView;
import com.hckjsec.cloud.service.IAppletsApplicantUserService;
import com.hckjsec.cloud.service.IAppletsBusinessMatterService;
import com.hckjsec.cloud.service.IAppletsBusinessService;
import com.hckjsec.common.core.controller.BaseController;
import com.hckjsec.common.core.domain.AjaxResult;
import com.hckjsec.common.core.domain.entity.SysDept;
import com.hckjsec.common.core.domain.entity.SysDictData;
import com.hckjsec.common.core.page.TableDataInfo;
import com.hckjsec.common.init.YwInitData;
import com.hckjsec.common.utils.*;
import com.hckjsec.system.domain.SysMatter;
import com.hckjsec.system.mapper.SysDeptMapper;
import com.hckjsec.system.service.ISysDeptService;
import com.hckjsec.system.service.ISysDictTypeService;
import com.hckjsec.system.service.ISysMatterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.*;

/**
 * 用户管理账户登录首页展示Controller
 *
 * @author cyt
 * @date 2021-08-23
 */
@Repository
@RestController
@RequestMapping("/system/administration")
public class AppletsAdministrationController extends BaseController {
    @Autowired
    private YwInitData ywInitData;

    @Autowired
    private ISysDeptService deptService;

    @Autowired
    private IAppletsBusinessService appletsBusinessService;

    @Autowired
    private IAppletsApplicantUserService appletsApplicantUserService;

    @Autowired
    private IAppletsBusinessMatterService appletsBusinessMatterService;

    @Autowired
    private ISysDictTypeService dictTypeService;

    @Autowired
    private ISysMatterService sysMatterService;


    @GetMapping(value = "/getHomeData")
    public AjaxResult getHomeData()
    {
        SysDept parentDept = deptService.selectDeptById(SecurityUtils.getDeptId());
        AdministrationView  administrationView = new AdministrationView();
        SysDept sysDept = new SysDept();
        sysDept.setParentId(parentDept.getParentId());
        sysDept.setDeptName("公证处");
        List<SysDept>  sysDeptList = deptService.selectDeptHomeList(sysDept);
        administrationView.setCompanyNum(sysDeptList.size());
        List<String> deptList = new ArrayList<>();
        List<SelectCurrencyHome> companyList = new ArrayList<>();
        SelectCurrencyHome allselectCurrencyHome = new SelectCurrencyHome();
        allselectCurrencyHome.setValue("-1");
        allselectCurrencyHome.setLabel("全部");
        companyList.add(allselectCurrencyHome);
        sysDeptList.forEach(kv->{
            SelectCurrencyHome selectCurrencyHome = new SelectCurrencyHome();
            selectCurrencyHome.setValue(String.valueOf(kv.getDeptId()));
            selectCurrencyHome.setLabel(kv.getDeptName());
            companyList.add(selectCurrencyHome);
            deptList.add(String.valueOf(kv.getDeptId()));
        });
        if (deptList.size() == 0){
             return AjaxResult.cloud_602("无下属机构");
        }
        administrationView.setCompanyList(companyList);
        //计算案件-总量
        String year = DateUtils.dateTimeNow(DateUtils.YYYY)+"-01-01";
        String month = DateUtils.dateTimeNow(DateUtils.YYYY_MM)+"-01";
        AppletsBusiness appletsBusiness = new AppletsBusiness();
        appletsBusiness.setBeginTime(year);
        List<Map<String, Integer>> yearListHt = appletsBusinessService.findDeptIdByNumMap(appletsBusiness);
        appletsBusiness.setBeginTime(month);
        List<Map<String, Integer>> monthListHt = appletsBusinessService.findDeptIdByNumMap(appletsBusiness);
        Map<String,String> yearMapHt = ComUtil.mapListByBigIntegerMap(yearListHt,"dept_id");
        Map<String,String> monthMapHt = ComUtil.mapListByBigIntegerMap(monthListHt,"dept_id");
        Integer yearNum = 0;
        Integer monthNum = 0;
        for (String jg : deptList){
            if (yearMapHt.containsKey(jg)){
                  yearNum+=Integer.valueOf(yearMapHt.get(jg));
            }
            if (monthMapHt.containsKey(jg)){
                  monthNum+=Integer.valueOf(monthMapHt.get(jg));
            }
        }
        administrationView.setYearAcceptNum(yearNum);
        administrationView.setMonthAcceptNum(monthNum);
        //计算案件-出证量
        AppletsBusiness IssueAppletsBusiness = new AppletsBusiness();
        IssueAppletsBusiness.setState("2");
        IssueAppletsBusiness.setBeginTime(year);
        List<Map<String, Integer>> yearIssueListHt = appletsBusinessService.findDeptIdByNumMap(IssueAppletsBusiness);
        IssueAppletsBusiness.setBeginTime(month);
        List<Map<String, Integer>> monthIssueListHt = appletsBusinessService.findDeptIdByNumMap(IssueAppletsBusiness);
        Map<String,String> yearIssueMapHt = ComUtil.mapListByBigIntegerMap(yearIssueListHt,"dept_id");
        Map<String,String> monthIssueMapHt = ComUtil.mapListByBigIntegerMap(monthIssueListHt,"dept_id");
        Integer yearIssueNum = 0;
        Integer monthIssueNum = 0;
        for (String jg : deptList){
            if (yearIssueMapHt.containsKey(jg)){
                yearIssueNum+=Integer.valueOf(yearIssueMapHt.get(jg));
            }
            if (monthIssueMapHt.containsKey(jg)){
                monthIssueNum+=Integer.valueOf(monthIssueMapHt.get(jg));
            }
        }
        administrationView.setYearIssueNum(yearIssueNum);
        administrationView.setMonthIssueNum(monthIssueNum);
        //计算费用
        BigDecimal yearMoney = new BigDecimal(0);
        BigDecimal monthMoney = new BigDecimal(0);
        AppletsBusiness MoneyAppletsBusiness = new AppletsBusiness();
        MoneyAppletsBusiness.setBeginTime(year);
        List<Map<String,BigDecimal>> moneyYearMap= appletsBusinessService.findDeptIdByMoneyMap(MoneyAppletsBusiness);
        MoneyAppletsBusiness.setBeginTime(month);
        List<Map<String,BigDecimal>> moneyMonthMap= appletsBusinessService.findDeptIdByMoneyMap(MoneyAppletsBusiness);
        Map<String,String> moneyYearHt = ComUtil.mapListByBigDecimalMap(moneyYearMap,"dept_id");
        Map<String,String> moneyMonthHt = ComUtil.mapListByBigDecimalMap(moneyMonthMap,"dept_id");
        for (String jg : deptList){
            if (moneyYearHt.containsKey(jg)){
                Double yeJe = Double.valueOf(moneyYearHt.get(jg));
                yearMoney=yearMoney.add(BigDecimal.valueOf(yeJe));
            }
            if (moneyMonthHt.containsKey(jg)){
                Double monJe = Double.valueOf(moneyMonthHt.get(jg));
                monthMoney=monthMoney.add(BigDecimal.valueOf(monJe));
            }
        }
        administrationView.setYearMoney(yearMoney);
        administrationView.setMonthMoney(monthMoney);
        //计算人员
        AppletsApplicantUser appletsApplicantUser = new AppletsApplicantUser();
        appletsApplicantUser.setBeginTime(year);
        List<Map<String, Integer>> yearUserListHt = appletsApplicantUserService.findDeptIdByUserNumMap(appletsApplicantUser);
        appletsApplicantUser.setBeginTime(month);
        List<Map<String, Integer>> monthUserListHt = appletsApplicantUserService.findDeptIdByUserNumMap(appletsApplicantUser);
        Map<String,String> yearUserMapHt = ComUtil.mapListByBigIntegerMap(yearUserListHt,"dept_id");
        Map<String,String> monthUserMapHt = ComUtil.mapListByBigIntegerMap(monthUserListHt,"dept_id");
        Integer yearUserNum = 0;
        Integer monthUserNum = 0;
        for (String jg : deptList){
            if (yearUserMapHt.containsKey(jg)){
                yearUserNum+=Integer.valueOf(yearUserMapHt.get(jg));
            }
            if (monthUserMapHt.containsKey(jg)){
                monthUserNum+=Integer.valueOf(monthUserMapHt.get(jg));
            }
        }
        administrationView.setYearUserNum(yearUserNum);
        administrationView.setMonthUserNum(monthUserNum);
        return AjaxResult.success(administrationView);
    }



    @GetMapping(value = "/getDeptList")
    public AjaxResult getDeptList()
    {
        SysDept parentDept = deptService.selectDeptById(SecurityUtils.getDeptId());
        List<SelectCurrencyHome> selectCurrencyHomeList = new ArrayList<>();
        AdministrationView  administrationView = new AdministrationView();
        SysDept sysDept = new SysDept();
        sysDept.setParentId(parentDept.getParentId());
        sysDept.setDeptName("公证处");
        List<SysDept>  sysDeptList = deptService.selectDeptHomeList(sysDept);
        sysDeptList.forEach(kv->{
            SelectCurrencyHome selectCurrencyHome = new SelectCurrencyHome();
            selectCurrencyHome.setValue(String.valueOf(kv.getDeptId()));
            selectCurrencyHome.setLabel(kv.getDeptName());
            selectCurrencyHomeList.add(selectCurrencyHome);
        });
        return AjaxResult.success(selectCurrencyHomeList);
    }


    //机构排名
    @PostMapping(value = "/getMechanismList")
    public AjaxResult getMechanismList(@RequestBody HomePageView homePageView)
    {
        SysDept parentDept = deptService.selectDeptById(SecurityUtils.getDeptId());
        String type = StringUtils.isHcNull(homePageView.getType(),"year");
        SysDept sysDept = new SysDept();
        sysDept.setParentId(parentDept.getParentId());
        sysDept.setDeptName("公证处");
        List<SysDept>  sysDeptList = deptService.selectDeptHomeList(sysDept);
        String year = DateUtils.dateTimeNow(DateUtils.YYYY)+"-01-01";
        String month = DateUtils.dateTimeNow(DateUtils.YYYY_MM)+"-01";
        AppletsBusiness appletsBusiness = new AppletsBusiness();
        if ("year".equals(type)){
            appletsBusiness.setBeginTime(year);
        }else{
            appletsBusiness.setBeginTime(month);
        }
        List<MechanismRanking> mechanismRankingList = new ArrayList<>();
        List<Map<String, Integer>> yearListHt = appletsBusinessService.findDeptIdByNumMap(appletsBusiness);
        Map<String,String> yearMapHt = ComUtil.mapListByBigIntegerMap(yearListHt,"dept_id");
        sysDeptList.forEach(kv->{
            MechanismRanking  mechanismRanking = new MechanismRanking();
            Integer sl = 0;
            String  jg = String.valueOf(kv.getDeptId());
            if (yearMapHt.containsKey(jg)){
                sl = Integer.valueOf(yearMapHt.get(jg));
            }
            mechanismRanking.setDeptName(kv.getDeptName());
            mechanismRanking.setNumber(sl);
            mechanismRankingList.add(mechanismRanking);
        });
        mechanismRankingList.sort(Comparator.comparing(MechanismRanking::getNumber));
        MechanismRankingData mechanismRankingData = new MechanismRankingData();
        List<String> nameList = new ArrayList<>();
        List<Integer> numList = new ArrayList<>();
        for (int i = 0; i < mechanismRankingList.size(); i++) {
            nameList.add(mechanismRankingList.get(i).getDeptName());
            numList.add(mechanismRankingList.get(i).getNumber());
        }
        mechanismRankingData.setName(nameList.stream().toArray(String[]::new));
        mechanismRankingData.setNumber(numList.stream().toArray(Integer[]::new));
        return AjaxResult.success(mechanismRankingData);
    }


    //前十事项排名
    @PostMapping(value = "/getMatterList")
    public AjaxResult getMatterList(@RequestBody HomePageView homePageView)
    {
        SysDept parentDept = deptService.selectDeptById(SecurityUtils.getDeptId());
        String mechanism = StringUtils.isHcNull(homePageView.getMechanism(),"-1");
        SysDept sysDept = new SysDept();
        sysDept.setParentId(parentDept.getParentId());
        sysDept.setDeptName("公证处");
        if (!"-1".equals(mechanism)){
            sysDept.setDeptId(Long.valueOf(mechanism));
        }
        List<SysDept>  sysDeptList = deptService.selectDeptHomeList(sysDept);
        List<Long> deptList = new ArrayList<>();
        sysDeptList.forEach(kv->{
            deptList.add(kv.getDeptId());
        });
        List<Map<String, Integer>> matterListHt = appletsBusinessMatterService.findMatterIdByNumMap(deptList.stream().toArray(Long[]::new));
        Map<String,String> matterMapHt = ComUtil.mapListByBigIntegerMap(matterListHt,"mattername");
        List<MechanismRanking> finalMechanismRankingList = new ArrayList<MechanismRanking>();
        matterMapHt.forEach((k, v)->{
            MechanismRanking  mechanismRanking = new MechanismRanking();
            mechanismRanking.setDeptName(k);
            mechanismRanking.setNumber(Integer.valueOf(v));
            finalMechanismRankingList.add(mechanismRanking);
        });
        List<MechanismRanking> MechanismRankingList = finalMechanismRankingList;
        MechanismRankingList.sort(Comparator.comparing(MechanismRanking::getNumber).reversed());
        int total = 10;
        if (MechanismRankingList.size()>total){
            MechanismRankingList=MechanismRankingList.subList(0, total);
        }
        MechanismRankingList.sort(Comparator.comparing(MechanismRanking::getNumber));
        MechanismRankingData mechanismRankingData = new MechanismRankingData();
        List<String> nameList = new ArrayList<>();
        List<Integer> numList = new ArrayList<>();
        for (int i = 0; i < MechanismRankingList.size(); i++) {
            nameList.add(MechanismRankingList.get(i).getDeptName());
            numList.add(MechanismRankingList.get(i).getNumber());
        }
        mechanismRankingData.setName(nameList.stream().toArray(String[]::new));
        mechanismRankingData.setNumber(numList.stream().toArray(Integer[]::new));
        return AjaxResult.success(mechanismRankingData);
    }


    //类别分布
    @PostMapping(value = "/getCategoryList")
    public AjaxResult getCategoryList(@RequestBody HomePageView homePageView)
    {
        SysDept parentDept = deptService.selectDeptById(SecurityUtils.getDeptId());
        String mechanism = StringUtils.isHcNull(homePageView.getMechanism(),"-1");
        SysDept sysDept = new SysDept();
        sysDept.setParentId(parentDept.getParentId());
        sysDept.setDeptName("公证处");
        if (!"-1".equals(mechanism)){
            sysDept.setDeptId(Long.valueOf(mechanism));
        }
        List<SysDept>  sysDeptList = deptService.selectDeptHomeList(sysDept);
        List<Long> deptList = new ArrayList<>();
        sysDeptList.forEach(kv->{
            deptList.add(kv.getDeptId());
        });
        List<Map<String, Integer>> categoryListHt = appletsBusinessService.findCategoryIdByNumMap(deptList.stream().toArray(Long[]::new));
        Map<String,String> categoryMapHt = ComUtil.mapListByBigIntegerMap(categoryListHt,"category");
        List<SysDictData> selectDictDataByType=dictTypeService.selectDictDataByType(ComUtil.CONFIG_CATEGORY);
        List<AppletsCategoryView> appletsCategoryViewList = new ArrayList<>();
        selectDictDataByType.forEach(kv->{
            AppletsCategoryView appletsCategoryView = new AppletsCategoryView();
            Integer sl =0;
            if (categoryMapHt.containsKey(kv.getDictValue())){
                sl = Integer.valueOf(categoryMapHt.get(kv.getDictValue()));
            }
            appletsCategoryView.setValue(sl);
            appletsCategoryView.setName(kv.getDictLabel());
            appletsCategoryViewList.add(appletsCategoryView);
        });
        return AjaxResult.success(appletsCategoryViewList);
    }


    //各月分布
    @PostMapping(value = "/getOperatortimeList")
    public AjaxResult getOperatortimeList(@RequestBody HomePageView homePageView)
    {
        SysDept parentDept = deptService.selectDeptById(SecurityUtils.getDeptId());
        String mechanism = StringUtils.isHcNull(homePageView.getMechanism(),"-1");
        SysDept sysDept = new SysDept();
        sysDept.setParentId(parentDept.getParentId());
        sysDept.setDeptName("公证处");
        if (!"-1".equals(mechanism)){
            sysDept.setDeptId(Long.valueOf(mechanism));
        }
        List<SysDept>  sysDeptList = deptService.selectDeptHomeList(sysDept);
        List<Long> deptList = new ArrayList<>();
        sysDeptList.forEach(kv->{
            deptList.add(kv.getDeptId());
        });
        List<Map<String, Integer>> operatortimeListHt = appletsBusinessService.findOperatortimeIdByNumMap(deptList.stream().toArray(Long[]::new));
        Map<String,String> operatortimeMapHt = ComUtil.mapListByBigIntegerMap(operatortimeListHt,"createTime");
        ArrayList<String> rqList= DateUtils.getPastMonthList(6);
        List<String []> rqDataList = new ArrayList<>();
        for (String  rq : rqList){
           String [] sj = new String[2];
           Integer sl = 0;
            if (operatortimeMapHt.containsKey(rq)){
                sl = Integer.valueOf(operatortimeMapHt.get(rq));
            }
            sj[0]=rq;
            sj[1]=sl+"";
            rqDataList.add(sj);
        }
        return AjaxResult.success(rqDataList);
    }

    //地图
    @PostMapping(value = "/getPlatList")
    public AjaxResult getPlatList(@RequestBody HomePageView homePageView)
    {
        SysDept parentDept = deptService.selectDeptById(SecurityUtils.getDeptId());
        String deptId = String.valueOf(parentDept.getParentId());
        if (!ComUtil.cityHt.containsKey(deptId)){
            return AjaxResult.cloud_602("所在机构未配置地图!");
        }
        PlatView platView = new PlatView();
        platView.setEname(ComUtil.cityHt.get(deptId)[0]);
        platView.setName(ComUtil.cityHt.get(deptId)[1]);
        platView.setJsondata(ComUtil.cityHt.get(deptId)[2]);
        List<String> countyList = Arrays.asList(ComUtil.cityHt.get(deptId)[3].split(","));
        String beginTime = StringUtils.isHcNull(homePageView.getBeginTime(),"");
        String endTime = StringUtils.isHcNull(homePageView.getEndTime(),"");
        AppletsBusiness appletsBusiness = new AppletsBusiness();
        AppletsApplicantUser appletsApplicantUser = new AppletsApplicantUser();
        if (!"".equals(beginTime)){
            appletsBusiness.setBeginTime(beginTime);
            appletsApplicantUser.setBeginTime(beginTime);
        }
        if (!"".equals(endTime)){
            appletsBusiness.setEndTime(endTime);
            appletsApplicantUser.setEndTime(endTime);
        }
        int max=0;
        List<Map<String, Integer>> caseListHt = appletsBusinessService.findDeptIdByNumMap(appletsBusiness);
        Map<String,String> caseMapHt = ComUtil.mapListByBigIntegerMap(caseListHt,"dept_id");
        List<Map<String, Integer>>  userListHt = appletsApplicantUserService.findDeptIdByUserNumMap(appletsApplicantUser);
        Map<String,String> userMapHt = ComUtil.mapListByBigIntegerMap(userListHt,"dept_id");
        List<PlatDataView> platData = new ArrayList<>();
        for (String county : countyList){
            PlatDataView platDataView = new PlatDataView();
            platDataView.setName(county);
            Integer allCaseSl = 0;
            Integer allUserSl = 0;
            List<PlatDataView2> notarydata = new ArrayList<>();
            String [] jgArr = ComUtil.cityCountyHt.get(county);
            for (int i = 0; i < jgArr.length; i++) {
                PlatDataView2 platDataView2 = new PlatDataView2();
                platDataView2.setName(ywInitData.getDeptMap().get(Long.valueOf(jgArr[i])));
                Integer caseSl = 0;
                Integer userSl = 0;
                if (caseMapHt.containsKey(jgArr[i])){
                    caseSl = Integer.valueOf(caseMapHt.get(jgArr[i]));
                }
                if (userMapHt.containsKey(jgArr[i])){
                    userSl = Integer.valueOf(userMapHt.get(jgArr[i]));
                }
                if (caseSl>max){
                    max = caseSl;
                }
                allCaseSl+=caseSl;
                allUserSl+=userSl;
                platDataView2.setValue(caseSl);
                platDataView2.setValue1(userSl);
                notarydata.add(platDataView2);
            }
            platDataView.setValue(allCaseSl);
            platDataView.setValue1(allUserSl);
            platDataView.setNotarydata(notarydata);
            platData.add(platDataView);
        }
        platView.setMax(max);
        platView.setPlatData(platData);
        return AjaxResult.success(platView);
    }


    //业务分析列表
    @PostMapping(value = "/getAnalysisList")
    public AjaxResult getAnalysisList(@RequestBody HomePageView homePageView)
    {
        SysDept parentDept = deptService.selectDeptById(SecurityUtils.getDeptId());
        AppletsBusiness appletsBusiness = new AppletsBusiness();
        appletsBusiness.setCategory(homePageView.getCategory());
        appletsBusiness.setPurpose(homePageView.getPurpose());
        appletsBusiness.setPlace(homePageView.getPlace());
        appletsBusiness.setBeginTime(homePageView.getBeginTime());
        appletsBusiness.setEndTime(homePageView.getEndTime());
        homePageView.setAllmatter(null);
        Map<String,Long[]> cityCountyHt=new Hashtable<String, Long[]>();
        SysDept sysDept = new SysDept();
        sysDept.setParentId(parentDept.getParentId());
        sysDept.setDeptName("公证处");
        List<SysDept>  sysDeptList = deptService.selectDeptHomeList(sysDept);
        sysDeptList.forEach(kv->{
            cityCountyHt.put(String.valueOf(kv.getDeptId()),new Long[]{0L,0L,0L,0L,0L});
        });
        List<AppletsBusiness> appletsBusinessList = appletsBusinessService.selectAdministrationBusinessList(appletsBusiness);
        appletsBusinessList.forEach(kv->{
             String deptids = String.valueOf(kv.getDeptId());
             if (cityCountyHt.containsKey(deptids)){
                 Long[] slArr = cityCountyHt.get(deptids);
                 if ("0".equals(kv.getState())){
                     slArr[0]=kv.getConfigId();
                 }else if("1".equals(kv.getState())){
                     slArr[1]=kv.getConfigId();
                 }else if("2".equals(kv.getState())){
                     slArr[2]=kv.getConfigId();
                 }else if("98".equals(kv.getState())){
                     slArr[3]=kv.getConfigId();
                 }else if("99".equals(kv.getState())){
                     slArr[4]=kv.getConfigId();
                 }
                 cityCountyHt.put(deptids,slArr);
             }
        });
        List<AnalysisAdministrationView> analysisAdministrationViewList = new ArrayList<>();
        cityCountyHt.forEach((k,v)->{
            AnalysisAdministrationView analysisAdministrationView = new AnalysisAdministrationView();
            analysisAdministrationView.setDeptId(Long.valueOf(k));
            analysisAdministrationView.setDeptName(ywInitData.getDeptMap().get(Long.valueOf(k)));
            Long[] slArr = v;
            analysisAdministrationView.setMaterialNum(slArr[0]);
            analysisAdministrationView.setNotApprovedNum(slArr[1]);
            analysisAdministrationView.setApprovedNum(slArr[2]);
            analysisAdministrationView.setRefuseNum(slArr[3]);
            analysisAdministrationView.setRevokeNum(slArr[4]);
            analysisAdministrationViewList.add(analysisAdministrationView);
        });
        return AjaxResult.success(analysisAdministrationViewList);
    }


    //业务分析列表2
    @PostMapping(value = "/getAnalysisBusinessList")
    public TableDataInfo getAnalysisBusinessList(@RequestBody HomePageView homePageView)
    {
        AppletsBusiness appletsBusiness = new AppletsBusiness();
        appletsBusiness.setDeptId(homePageView.getDeptId());
        appletsBusiness.setState(homePageView.getState());
        appletsBusiness.setCategory(homePageView.getCategory());
        appletsBusiness.setPurpose(homePageView.getPurpose());
        appletsBusiness.setPlace(homePageView.getPlace());
        appletsBusiness.setBeginTime(homePageView.getBeginTime());
        appletsBusiness.setEndTime(homePageView.getEndTime());
        List<AppletsBusiness> list = appletsBusinessService.selectAppletsBusinessList(appletsBusiness);
        return getDataTable(list);
    }



    //业务分析列表-类别
    @PostMapping(value = "/getAnalysisCategoryList")
    public AjaxResult getAnalysisCategoryList(@RequestBody HomePageView homePageView)
    {
        SysDept parentDept = deptService.selectDeptById(SecurityUtils.getDeptId());
        AppletsBusiness appletsBusiness = new AppletsBusiness();
        appletsBusiness.setPurpose(homePageView.getPurpose());
        appletsBusiness.setPlace(homePageView.getPlace());
        appletsBusiness.setBeginTime(homePageView.getBeginTime());
        appletsBusiness.setEndTime(homePageView.getEndTime());
        homePageView.setAllmatter(null);
        Map<String,Long[]> cityCountyHt=new Hashtable<String, Long[]>();
        SysDept sysDept = new SysDept();
        sysDept.setParentId(parentDept.getParentId());
        sysDept.setDeptName("公证处");
        List<SysDept>  sysDeptList = deptService.selectDeptHomeList(sysDept);
        sysDeptList.forEach(kv->{
            cityCountyHt.put(String.valueOf(kv.getDeptId()),new Long[]{0L,0L,0L,0L});
        });
        List<AppletsBusiness> appletsBusinessList = appletsBusinessService.selectAdministrationCategoryList(appletsBusiness);
        appletsBusinessList.forEach(kv->{
            String deptids = String.valueOf(kv.getDeptId());
            if (cityCountyHt.containsKey(deptids)){
                Long[] slArr = cityCountyHt.get(deptids);
                if ("1001".equals(kv.getCategory())){
                    slArr[0]=kv.getConfigId();
                }else if("1002".equals(kv.getCategory())){
                    slArr[1]=kv.getConfigId();
                }else if("1003".equals(kv.getCategory())){
                    slArr[2]=kv.getConfigId();
                }else if("1004".equals(kv.getCategory())){
                    slArr[3]=kv.getConfigId();
                }
                cityCountyHt.put(deptids,slArr);
            }
        });
        List<AnalysisAdministrationCategoryView> analysisAdministrationViewList = new ArrayList<>();
        cityCountyHt.forEach((k,v)->{
            AnalysisAdministrationCategoryView analysisAdministrationView = new AnalysisAdministrationCategoryView();
            analysisAdministrationView.setDeptId(Long.valueOf(k));
            analysisAdministrationView.setDeptName(ywInitData.getDeptMap().get(Long.valueOf(k)));
            Long[] slArr = v;
            analysisAdministrationView.setDomesticNum(slArr[0]);
            analysisAdministrationView.setAbroadNum(slArr[1]);
            analysisAdministrationView.sethKongMacaoNum(slArr[2]);
            analysisAdministrationView.setTaiWanNum(slArr[3]);
            analysisAdministrationViewList.add(analysisAdministrationView);
        });
        return AjaxResult.success(analysisAdministrationViewList);
    }


    //业务分析列表-事项
    @PostMapping(value = "/getAnalysisMatterList")
    public AjaxResult getAnalysisMatterList(@RequestBody HomePageView homePageView)
    {
        List<SysMatter> SysMatterList=sysMatterService.selectSysMatterByIdLength("4");
        String beginYearTime = DateUtils.dateTimeNow(DateUtils.YYYY)+"-01-01";
        String endYearTime = DateUtils.dateTimeNow(DateUtils.YYYY)+"-12-31";
        String beginLastYearTime = DateUtils.getPastYeat(1)+"-01-01";
        String endLastYearTime = DateUtils.getPastYeat(1)+"-12-31";
        AppletsBusinessMatter appletsBusinessMatter = new AppletsBusinessMatter();
        appletsBusinessMatter.setDeptId(homePageView.getDeptId());
        appletsBusinessMatter.setBeginTime(beginYearTime);
        appletsBusinessMatter.setEndTime(endYearTime);
        List<AppletsBusinessMatter>  yearList = appletsBusinessMatterService.selectAdministrationMatterList(appletsBusinessMatter);
        appletsBusinessMatter.setBeginTime(beginLastYearTime);
        appletsBusinessMatter.setEndTime(endLastYearTime);
        List<AppletsBusinessMatter>  yearLastList = appletsBusinessMatterService.selectAdministrationMatterList(appletsBusinessMatter);
        Map<String,Long[]> dataHt=new Hashtable<String, Long[]>();
        SysMatterList.forEach(kv->{
            dataHt.put(kv.getMatterNumber(),new Long[]{0L,0L});
        });
        yearList.forEach(kv->{
            String mattid = kv.getMatter();
            if (dataHt.containsKey(mattid)){
                Long[] slArr = dataHt.get(mattid);
                slArr[0]=kv.getConfigId();
                dataHt.put(mattid,slArr);
            }
        });
        yearLastList.forEach(kv->{
            String mattid = kv.getMatter();
            if (dataHt.containsKey(mattid)){
                Long[] slArr = dataHt.get(mattid);
                slArr[1]=kv.getConfigId();
                dataHt.put(mattid,slArr);
            }
        });
        List<AnalysisAdministrationMatterView> rateList = new ArrayList<>();
        SysMatterList.forEach(kv->{
            AnalysisAdministrationMatterView analysisAdministrationMatterView = new AnalysisAdministrationMatterView();
            String mattid = kv.getMatterNumber();
            analysisAdministrationMatterView.setMatter(mattid);
            analysisAdministrationMatterView.setMatterName(kv.getMatterName());
            Long[] slArr = dataHt.get(mattid);
            analysisAdministrationMatterView.setThatYearNum(slArr[0]);
            analysisAdministrationMatterView.setLastYearNum(slArr[1]);
            analysisAdministrationMatterView.setRate(GrowthRate.getAnalysisData(slArr[0].intValue(),slArr[1].intValue()));
            rateList.add(analysisAdministrationMatterView);
        });
        return AjaxResult.success(rateList);
    }
}
